package com.zetatech.bdp.writer.hive

import java.sql.DriverManager
import java.util

import com.zetatech.bdp.entity.{ColumnDef, HiveWriter}

import scala.collection.JavaConverters._
import scala.collection.mutable

object Test {

  def main(args: Array[String]): Unit = {

    //
    val HiveWriterHandler = new HiveWriterHandler

    //连接信息
    val writer = new HiveWriter
    writer.setDefaultFS("hdfs://bdptest1:8020")
    writer.setStore("parquet")
    writer.setDatabase("default")
    writer.setTable("testuser")
    // var mapConfig = util.HashMap[String,String]
    val mapConfig = mutable.HashMap[String, String]()
    //mapConfig.put("outPutPath", "/root/test2/TestUser.txt")
    mapConfig.put("hiveJdbcUrl", "jdbc:hive2://bdptest2:10000")
    mapConfig.put("user", "root")
    mapConfig.put("password", "zeta@123456")
    mapConfig.put("password", "zeta@123456")



  //  Class.forName("org.apache.hive.jdbc.HiveDriver")
//    val conn = DriverManager.getConnection("jdbc:hive2://bdptest2:10000", "root", "zeta@123456")
//    val stmt = conn.createStatement()
//    stmt.execute("load data inpath 'hdfs://bdptest1:8020/root/test2/TestUser.txt' overwrite into table TestUser")



    writer.setConf(mapConfig.toMap.asJava)



    //schemas
    val columnDefs = mutable.MutableList[ColumnDef]()

    val columnDef0 = new ColumnDef()
    columnDef0.setName("id")
    columnDefs += (columnDef0)

    val columnDef1 = new ColumnDef()
    columnDef1.setName("name")
    columnDefs += (columnDef1)


    val columnDef2 = new ColumnDef()
    columnDef2.setName("age")
    columnDefs += (columnDef2)


    val columnDef3 = new ColumnDef()
    columnDef3.setName("address")
    columnDefs += (columnDef3)


    val columnDef4 = new ColumnDef()
    columnDef4.setName("phone")
    columnDefs += (columnDef4)

    //  println(columnDefs.mkString)
    //datas
    /**
      * var i: Int = 1
      * while ( { i < 30})  { sb.append(1 + ",")
      *sb.append("name_" + i + ",")
      *sb.append(i + 10 + ",")
      *sb.append("天府 " + i + " 街" + ",")
      *sb.append(1858246338 + i + "\n")
      * *
      * {i += 1; i - 1}}
      */
    val datas = mutable.MutableList[util.Map[String, String]]()
    for (i <- 1 to  5000) {
      val javaScores = new java.util.HashMap[String, String]()
      javaScores.put("id", i.toString)
      javaScores.put("name", "name_"+i)
      javaScores.put("age", i.toString)
      javaScores.put("address", "天府" + i + "街")
      javaScores.put("phone", "18866668888")
      //val map:scala.collection.mutable.Map[String, Int] =
//      for(i <-10 to 50){
//        javaScores.put()
//      }
      datas += javaScores
    }
   // println(datas)
   HiveWriterHandler.write(writer, columnDefs.toList.asJava, datas.asJava)

  }

}
